home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 22 / CU Amiga Magazine's Super CD-ROM 22 (1998)(EMAP Images)(GB)[!][issue 1998-05].iso / PowerPC / System / PPCReleaseDEV / Examples / TaskASemaphore.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-02-21  |  1.7 KB  |  81 lines

  1. #include <exec/types.h>
  2. #include <exec/nodes.h>
  3. #include <exec/lists.h>
  4. #include <exec/memory.h>
  5. #include <powerup/ppclib/interface.h>
  6. #include <powerup/ppclib/semaphore.h>
  7. #include <powerup/gcclib/powerup_protos.h>
  8.  
  9. #define    SEMAPHORENAME    "TaskSemaphore"
  10.  
  11. char    Buffer[]="0:Task A is active\n";
  12.  
  13. ULONG main(void)
  14. {
  15. BPTR        MyFile;
  16. ULONG        MySignal;
  17. void        *Semaphore;
  18. BOOL        MySemaphore;
  19. BOOL        ObtainedByName;
  20. struct TagItem    MyTags[10];
  21. int        i;
  22.  
  23.   MySemaphore        =    FALSE;
  24.   ObtainedByName    =    TRUE;
  25.   if ((Semaphore=PPCObtainSemaphoreByName(SEMAPHORENAME))==NULL)
  26.   {
  27.     MyTags[0].ti_Tag    =    PPCSEMAPHORETAG_NAME;
  28.     MyTags[0].ti_Data    =    (ULONG) SEMAPHORENAME;
  29.     MyTags[1].ti_Tag    =    TAG_DONE;
  30.     if ((Semaphore=PPCCreateSemaphore(MyTags))==NULL)
  31.     {
  32.       if ((Semaphore=PPCObtainSemaphoreByName(SEMAPHORENAME))==NULL)
  33.       {
  34.         /*
  35.          * CreateSemaphore didn`t work and that wasn`t caused by a parallel TaskB
  36.          * running
  37.          */
  38.         return(20);
  39.       }
  40.     }
  41.     else
  42.     {
  43.       MySemaphore    =    TRUE;
  44.       ObtainedByName    =    FALSE;
  45.     }
  46.   }
  47.  
  48.   if (MyFile=PPCOpen("con:0/0/640/200/TaskA/CLOSE",MODE_NEWFILE))
  49.   {
  50.     for (;;)
  51.     {
  52.       if (!ObtainedByName)
  53.       {
  54.         PPCObtainSemaphore(Semaphore);
  55.       }
  56.       for (i=0;i<10;i++)
  57.       {
  58.         Buffer[0]    =    '0'+i;
  59.         PPCWrite(MyFile,
  60.                  Buffer,
  61.                  sizeof(Buffer));
  62.       }
  63.       PPCReleaseSemaphore(Semaphore);
  64.       ObtainedByName    =    FALSE;
  65.     }
  66.     PPCClose(MyFile);
  67.   }
  68.   else
  69.   {
  70.     PPCRawDoFmt("Couldn`t open CLI Window\n",
  71.                 NULL,
  72.                 1,                /* 0=Buffer,1=serial <> NOT supported yet */
  73.                 NULL);
  74.   }
  75.   if (MySemaphore)
  76.   {
  77.     PPCDeleteSemaphore(Semaphore);
  78.   }
  79.   return(0);
  80. }
  81.